package com.my.xadmin.security.repository;

import com.my.framework.base.repository.BaseJpaDao;
import com.my.xadmin.security.entity.Organization;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import javax.persistence.QueryHint;
import java.util.List;


public interface OrganizationDAO extends BaseJpaDao<Organization, Long>
{
    Page<Organization> findByParentId(Long parentId, Pageable pageable);
    
    Page<Organization> findByParentIdAndNameContaining(Long parentId, String name, Pageable pageable);
    
//    @QueryHints(value = {@QueryHint(name = "org.hibernate.cacheable", value = "true"),
//        @QueryHint(name = "org.hibernate.cacheRegion", value = "com.wondersgroup.framework.entity.main")})
    @Query("from Organization")
    List<Organization> findAllWithCache();
    
    Organization findByCodeAndJglx(String orgCode, String jglx);
    @Query(value="SELECT * from security_organization WHERE code = ?1",nativeQuery=true)
    Organization findByCode(String code);
    
    List<Organization> findByParentId(Long parentId);
    
    @Query("from Organization o where o.areaCode like ?1")
    List<Organization> findByAreaCode(String areaCode);
    
    Organization findByAreaCodeAndJglx(String areaCode, String jglx);
    
    Organization findByAreaCodeAndJglxAndCode(String areaCode, String jglx, String code);

    List<Organization> findByTbbzAndIsRoot(String tbbz, Boolean flag);


    Object findByName(String name);
}
